package com.comment.service;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.comment.domain.Comment;
import com.comment.util.HibernateUtils;


public class CommentService {
	@SuppressWarnings("unchecked")
	public List<Comment> findAllComment() {
		Session session = HibernateUtils.getSession();
		Query query = session.createQuery("from Comment");
		List<Comment> list = query.list();
		session.close();
		return list;
	}

	public void insertComment(Comment comment) {
		Session session = HibernateUtils.getSession();
		Transaction tx = session.beginTransaction();
		try {
			session.save(comment);
			tx.commit();
		} catch (HibernateException e) {
			tx.rollback();
			throw e;
		} finally {
			session.close();
		}
	}
}
